package com.souku.finance.application.ui.more;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jungly.gridpasswordview.GridPasswordView;
import com.souku.finance.application.R;
import com.souku.finance.application.base.BaseActivity;

/**
 * Created by Android on 2016/12/22.
 */

public class ResetPayPassActivity extends BaseActivity implements View.OnClickListener {

    protected RelativeLayout topBack;
    protected TextView topTitle;
    protected GridPasswordView pswView;
    protected TextView tvForget;
    protected Button btnOk;
    protected TextView tvDec;
    private int step = 0;

    @Override
    public void internet() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.act_resetpaypass);
        initView();
        pswView.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
            @Override
            public void onTextChanged(String psw) {
                btnOk.setBackgroundResource(R.drawable.solid_gray_round);
                btnOk.setEnabled(false);
            }

            @Override
            public void onInputFinish(String psw) {
                if (step == 0) {
                    step++;
                    setData();
                } else if (step == 1) {
                    step++;
                    setData();
                } else if (step == 2) {
                    btnOk.setBackgroundResource(R.drawable.solid_main_round);
                    btnOk.setEnabled(true);
                }
            }
        });

        topTitle.setText("修改交易密码");
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.top_back) {
            finish();
        } else if (view.getId() == R.id.tv_forget) {

        } else if (view.getId() == R.id.btn_ok) {

        }
    }

    private void initView() {
        topBack = (RelativeLayout) findViewById(R.id.top_back);
        topBack.setOnClickListener(ResetPayPassActivity.this);
        topTitle = (TextView) findViewById(R.id.top_title);
        pswView = (GridPasswordView) findViewById(R.id.pswView);
        tvForget = (TextView) findViewById(R.id.tv_forget);
        tvForget.setOnClickListener(ResetPayPassActivity.this);
        btnOk = (Button) findViewById(R.id.btn_ok);
        btnOk.setOnClickListener(ResetPayPassActivity.this);
        tvDec = (TextView) findViewById(R.id.tv_dec);
    }

    private void setData() {
        pswView.clearPassword();
        switch (step) {
            case 0:
                tvDec.setText("请输入当前交易密码，以验证身份");
                tvForget.setVisibility(View.VISIBLE);
                btnOk.setVisibility(View.GONE);
                btnOk.setEnabled(false);
                btnOk.setBackgroundResource(R.drawable.solid_gray_round);
                break;
            case 1:
                tvDec.setText("请输入新的交易密码");
                tvForget.setVisibility(View.GONE);
                btnOk.setVisibility(View.GONE);
                btnOk.setEnabled(false);
                btnOk.setBackgroundResource(R.drawable.solid_gray_round);
                break;
            case 2:
                tvDec.setText("请再次输入以确认");
                tvForget.setVisibility(View.GONE);
                btnOk.setVisibility(View.VISIBLE);
                btnOk.setEnabled(false);
                btnOk.setBackgroundResource(R.drawable.solid_gray_round);
                break;

        }
    }

    @Override
    public void onBackPressed() {
        if (step != 0) {
            step--;
            setData();
        } else {
            super.onBackPressed();
        }
    }
}
